﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace THO7_Team8.Dialogs
{
    public partial class MatchMaker : Form
    {
        public MatchMaker()
        {
            InitializeComponent();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            textBox1.Enabled = ((CheckBox)sender).Checked;
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            textBox2.Enabled = ((CheckBox)sender).Checked;
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            textBox3.Enabled = ((CheckBox)sender).Checked;
        }

        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {
            textBox4.Enabled = ((CheckBox)sender).Checked;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String commonCharacters = "";
            int numberOfCheckedItems = 0;
            TextBox[] boxes = new TextBox[4];
            boxes[0] = textBox1;
            boxes[1] = textBox2;
            boxes[2] = textBox3;
            boxes[3] = textBox4;

            int counter = 1;
            foreach (TextBox t in boxes)
            {
                if (t.Enabled)
                {
                    if (commonCharacters.Length == 0)
                    {
                        commonCharacters = t.Text;
                        counter++;
                    }
                    else
                    {
                        commonCharacters = getCommonCharacters(commonCharacters, t.Text);
                        counter++;
                    }
                }
                else
                {
                    counter++;
                }
            }
            textBox5.Text = commonCharacters;
        }
        private String getCommonCharacters(String first, String second)
        {
            String _commonchars = "";
            foreach (char c in first)
            {
                if (second.IndexOf(c) != -1)
                {
                    _commonchars += c;
                }
            }
            return _commonchars;
        }
    }
}
